home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / xinetd.2 / xinetd / xinetd.2.1.7-linux.4 / libs / src / timer / timemacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-25  |  3.5 KB  |  117 lines

  1. /*
  2.  * (c) Copyright 1993 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef __TIMEMACROS_H
  8. #define __TIMEMACROS_H
  9.  
  10. /*
  11.  * $Id: timemacros.h,v 3.1 1992/11/23 16:22:53 panos Exp $
  12.  */
  13.  
  14. #include <sys/types.h>
  15. #include <sys/time.h>
  16.  
  17. /*
  18.  * Define a few relevant NULL values
  19.  */
  20. #ifndef TIMEZONE_NULL
  21. #define TIMEZONE_NULL        ((struct timezone *)0)
  22. #endif
  23. #ifndef TIMEVAL_NULL
  24. #define TIMEVAL_NULL            ((struct timeval *)0)
  25. #endif
  26. #ifndef ITIMERVAL_NULL
  27. #define ITIMERVAL_NULL        ((struct itimerval *)0)
  28. #endif
  29.  
  30. /*
  31.  * The TV_* macros work with timeval structures.
  32.  * The TVP_* macros work with pointers to timeval structures.
  33.  *
  34.  * We support the following operations:
  35.  *
  36.  *            EQ( tv1, tv2 )            : tv1 == tv2
  37.  *            NE( tv1, tv2 )            : tv1 != tv2
  38.  *            LT( tv1, tv2 )            : tv1 <  tv2
  39.  *            LE( tv1, tv2 )            : tv1 <= tv2
  40.  *            GT( tv1, tv2 )            : tv1 >  tv2
  41.  *            GE( tv1, tv2 )            : tv1 >= tv2
  42.  *            ISZERO( tv )            : tv == 0
  43.  *            ZERO( tv )                : tv = 0
  44.  *            ADD( res, tv1, tv2 ) : res = tv1 + tv2
  45.  *            SUB( res, tv1, tv2 ) : res = tv1 = tv2
  46.  *
  47.  * We normalize the result after addition and subtraction.
  48.  */
  49.  
  50. #define __ONE_MILLION                    1000000
  51.  
  52. #define TV_ADD( tv_res, tv1, tv2 )                                    \
  53.     {                                                                            \
  54.         (tv_res).tv_sec = (tv1).tv_sec + (tv2).tv_sec ;            \
  55.         (tv_res).tv_usec = (tv1).tv_usec + (tv2).tv_usec ;        \
  56.         if ( (tv_res).tv_usec >= __ONE_MILLION )                    \
  57.         {                                                                        \
  58.             (tv_res).tv_sec++ ;                                            \
  59.             (tv_res).tv_usec -= __ONE_MILLION ;                        \
  60.         }                                                                        \
  61.     }
  62.  
  63. #define TV_SUB( tv_res, tv1, tv2 )                                    \
  64.     {                                                                            \
  65.         (tv_res).tv_sec = (tv1).tv_sec - (tv2).tv_sec ;            \
  66.         (tv_res).tv_usec = (tv1).tv_usec - (tv2).tv_usec ;        \
  67.         if ( (tv_res).tv_usec < 0 )                                    \
  68.         {                                                                        \
  69.             (tv_res).tv_usec += __ONE_MILLION ;                        \
  70.             (tv_res).tv_sec-- ;                                            \
  71.         }                                                                        \
  72.     }
  73.  
  74. #define TV_LT( tv1, tv2 )                                                                    \
  75.         ( (tv1).tv_sec < (tv2).tv_sec ||                                                    \
  76.           (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec < (tv2).tv_usec )
  77.  
  78. #define TV_LE( tv1, tv2 )                                                                    \
  79.         ( (tv1).tv_sec < (tv2).tv_sec ||                                                    \
  80.           (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec <= (tv2).tv_usec )
  81.  
  82. #define TV_GT( tv1, tv2 )                                                                    \
  83.         ( (tv1).tv_sec > (tv2).tv_sec ||                                                    \
  84.           (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec > (tv2).tv_usec )
  85.  
  86. #define TV_GE( tv1, tv2 )                                                                    \
  87.         ( (tv1).tv_sec > (tv2).tv_sec ||                                                    \
  88.           (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec >= (tv2).tv_usec )
  89.  
  90. #define TV_EQ( tv1, tv2 )                                                                    \
  91.         ( (tv1).tv_sec == (tv2).tv_sec && (tv1).tv_usec == (tv2).tv_usec )
  92.  
  93. #define TV_NE( tv1, tv2 )                                                                    \
  94.         ( (tv1).tv_sec != (tv2).tv_sec || (tv1).tv_usec != (tv2).tv_usec )
  95.  
  96. #define TV_ISZERO( tv )            ( (tv).tv_sec == 0 && (tv).tv_usec == 0 )
  97.  
  98. #define TV_ZERO( tv )            (tv).tv_sec = (tv).tv_usec = 0
  99.  
  100.  
  101. /*
  102.  * Pointer macros
  103.  */
  104.  
  105. #define TVP_ADD( tvp_res, tvp1, tvp2 )    TV_ADD( *(tvp_res), *(tvp1), *(tvp2) )
  106. #define TVP_SUB( tvp_res, tvp1, tvp2 )    TV_SUB( *(tvp_res), *(tvp1), *(tvp2) )
  107. #define TVP_LT( tvp1, tvp2 )                TV_LT( *(tvp1), *(tvp2) )
  108. #define TVP_LE( tvp1, tpv2 )                TV_LE( *(tvp1), *(tvp2) )
  109. #define TVP_GT( tvp1, tvp2 )                TV_GT( *(tvp1), *(tvp2) )
  110. #define TVP_GE( tvp1, tvp2 )                TV_GE( *(tvp1), *(tvp2) )
  111. #define TVP_EQ( tvp1, tvp2 )                TV_EQ( *(tvp1), *(tvp2) )
  112. #define TVP_NE( tvp1, tvp2 )                TV_NE( *(tvp1), *(tvp2) )
  113. #define TVP_ISZERO( tvp )                    TV_ISZERO( *(tvp) )
  114. #define TVP_ZERO( tvp )                        TV_ZERO( *(tvp) )
  115.  
  116. #endif    /* __TIMEMACROS_H */
  117.